﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using E = com.bodurov.SilverlightControls.XmlCodeEditor.Enums.XmlElement;
using A = com.bodurov.SilverlightControls.XmlCodeEditor.Enums.XmlArea;

namespace com.bodurov.SilverlightControls.XmlCodeEditor.Tests
{
    [TestClass]//[Ignore]
    public class IterativeTokenizerCanParseIncomplete : BaseTokenFixture
    {
        //"<a href='/Home.html' style=\"border:solid 1px red\" "
        [TestMethod]//[Ignore]
        public void CanParseIncomplete_Case_1()
        {
            var str = Lines("<!DOCTYPE html<html ");

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //BuildAssertions(tokens);
            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("!DOCTYPE", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("html", E.AttributeName),
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("html", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace)));

        }

        [TestMethod]//[Ignore]
        public void CanParseIncomplete_Case_2()
        {
            var str = Lines("<a href='/Home.html' style=\"border:solid 1px red\" ",
                            "<newtag");

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //BuildAssertions(tokens);
            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("a", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("href", E.AttributeName),
                    Expect("=", E.AttributeEqualSign),
                    Expect("'/Home.html'", E.AttributeSingleQuoteString),
                    Expect(" ", E.WhiteSpace),
                    Expect("style", E.AttributeName),
                    Expect("=", E.AttributeEqualSign),
                    Expect("\"border:solid 1px red\"", E.AttributeDualQuoteString),
                    Expect(" ", E.WhiteSpace),
                    Expect_NewLine,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("newtag", E.OpeningTagName)));

        }

        [TestMethod]//[Ignore]
        public void CanParseIncomplete_Case_3()
        {
            var str = Lines("<abc",
                            "< <cde");

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //BuildAssertions(tokens);
            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("abc", E.OpeningTagName),
                    Expect_NewLine,
                    Expect("< ", E.OutsideTagContent),
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("cde", E.OpeningTagName)));

        }


        [TestMethod]//[Ignore]
        public void CanParseIncomplete_Case_4()
        {
            var str = Lines("        <table><abc id=\"sdf");

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //BuildAssertions(tokens);
            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.OutsideTag,
                    Expect("        ", E.OutsideTagContent)),
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("table", E.OpeningTagName),
                    Expect(">", E.OpeningTagEndBracket),
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("abc", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("id", E.AttributeName),
                    Expect("=", E.AttributeEqualSign),
                    Expect("\"sdf", E.AttributeDualQuoteString)));

        }


        [TestMethod]//[Ignore]
        public void CanParseIncomplete_Case_5()
        {
            var str = Lines(
                    "       <div class=\"topLinks\">",
                    "          <a href=\"http://blog.bodurov.com\">",
                    "            myBLOG",
                    "          </a>",
                    "          &nbsp; &nbsp;",
                    "          <a href=\"javascript:void(0);\" ",
                    "              onClick=\"document.location.href='mailto:Vladimir Bodurov <conta'+'ct'+'\x40'+'bo'+'durov'+'.'+'com>';void(0);\">",
                    "            contact",
                    "          </a>",
                    "        </div>"
                );

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //BuildAssertions(tokens);
            //TraceTokens(tokens);
            AssertTokens(tokens,
                Within(A.OutsideTag,
                    Expect("       ", E.OutsideTagContent)),
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("div", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("class", E.AttributeName),
                    Expect("=", E.AttributeEqualSign),
                    Expect("\"topLinks\"", E.AttributeDualQuoteString),
                    Expect(">", E.OpeningTagEndBracket)),
                Within(A.OutsideTag,
                    Expect_NewLine,
                    Expect("          ", E.OutsideTagContent)),
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("a", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("href", E.AttributeName),
                    Expect("=", E.AttributeEqualSign),
                    Expect("\"http://blog.bodurov.com\"", E.AttributeDualQuoteString),
                    Expect(">", E.OpeningTagEndBracket)),
                Within(A.OutsideTag,
                    Expect_NewLine,
                    Expect("            myBLOG", E.OutsideTagContent),
                    Expect_NewLine,
                    Expect("          ", E.OutsideTagContent)),
                Within(A.InsideTag,
                    Expect("</", E.ClosingTagBeginBracket),
                    Expect("a", E.ClosingTagName),
                    Expect(">", E.ClosingTagEndBracket)),
                Within(A.OutsideTag,
                    Expect_NewLine,
                    Expect("          ", E.OutsideTagContent),
                    Expect("&nbsp;", E.Entity),
                    Expect(" ", E.OutsideTagContent),
                    Expect("&nbsp;", E.Entity),
                    Expect_NewLine,
                    Expect("          ", E.OutsideTagContent)),
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("a", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("href", E.AttributeName),
                    Expect("=", E.AttributeEqualSign),
                    Expect("\"javascript:void(0);\"", E.AttributeDualQuoteString),
                    Expect(" ", E.WhiteSpace),
                    Expect_NewLine,
                    Expect("              ", E.WhiteSpace),
                    Expect("onClick", E.AttributeName),
                    Expect("=", E.AttributeEqualSign),
                    Expect("\"document.location.href='mailto:Vladimir Bodurov <conta'+'ct'+'@'+'bo'+'durov'+'.'+'com>';void(0);\"", E.AttributeDualQuoteString),
                    Expect(">", E.OpeningTagEndBracket)),
                Within(A.OutsideTag,
                    Expect_NewLine,
                    Expect("            contact", E.OutsideTagContent),
                    Expect_NewLine,
                    Expect("          ", E.OutsideTagContent)),
                Within(A.InsideTag,
                    Expect("</", E.ClosingTagBeginBracket),
                    Expect("a", E.ClosingTagName),
                    Expect(">", E.ClosingTagEndBracket)),
                Within(A.OutsideTag,
                    Expect_NewLine,
                    Expect("        ", E.OutsideTagContent)),
                Within(A.InsideTag,
                    Expect("</", E.ClosingTagBeginBracket),
                    Expect("div", E.ClosingTagName),
                    Expect(">", E.ClosingTagEndBracket)));

        }



        //"            <a href="/Clubhouse
        //    <cms:NewsObjectProperty runat="server"
        //        PropertyName="Path" />
        //">
       /* [TestMethod]//[Ignore]
        public void CanParseIncomplete_Case_6()
        {
            var str = Lines(@"            <a href=""/Clubhouse
    <cms:NewsObjectProperty runat=""server""
        PropertyName=""Path"" />
'>");

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //BuildAssertions(tokens);
            TraceTokens(tokens);

           

        }*/
    }
}
